﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_QLSV.BusinessClassLibrary
{
    public class LopMonHocBUS
    {
        private static QLSVDataContext db = new QLSVDataContext();
        public static bool ThemLop_MonHoc(Lop_MonHoc Lop_MonHoc)
        {
            try
            {
                db.Lop_MonHocs.InsertOnSubmit(Lop_MonHoc);
                db.SubmitChanges();
            }
            catch
            {
                //conflict primary key - the item is exist
                return false;
            }
            return true;
        }
        public static bool XoaLop_MonHoc(string idlop, string idmonhoc)
        {
            try
            {
                Lop_MonHoc old = db.Lop_MonHocs.Single(kh => kh.masolop==idlop&&kh.masomonhoc==idmonhoc);
                db.Lop_MonHocs.DeleteOnSubmit(old);
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        //public static bool CapNhatLop_MonHocHoc(string id, Lop_MonHoc Lop_MonHoc)
        //{
        //    try
        //    {
        //        Lop_MonHoc old = db.Lop_MonHocs.Single(kh => kh.masoLop_MonHoc == id);
        //        old.tenLop_MonHoc = Lop_MonHoc.tenLop_MonHoc;
        //        db.SubmitChanges();
        //    }
        //    catch
        //    {
        //        // the item is not exist
        //        return false;
        //    }
        //    return true;
        //}
        public static List<Lop_MonHoc> LayDanhSach()
        {
            return db.Lop_MonHocs.ToList();
        }
    }
}
